package com.lyfei.yd.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lyfei.yd.system.domain.entity.Cart;
import com.lyfei.yd.system.mapper.CartMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("cartService")
public class CartService extends BaseService<CartMapper, Cart> {
    public List<Cart> getByUserId(Long userId) {
        return this.list(new LambdaQueryWrapper<Cart>()
                .eq(Cart::getUserId, userId)
                .eq(Cart::getDeleted, 0));
    }

    public Cart getCart(Long userId, Long productId, Long goodsId) {
        return this.getOne(new LambdaQueryWrapper<Cart>()
                .eq(Cart::getUserId, userId)
                .eq(Cart::getGoodsProductId, productId)
                .eq(Cart::getGoodsId, goodsId)
                .eq(Cart::getDeleted, 0));
    }

    public List<Cart> getCheckedByUserId(Long userId) {
        return this.list(new LambdaQueryWrapper<Cart>()
                .eq(Cart::getUserId, userId)
                .eq(Cart::getChecked, 1)
                .eq(Cart::getDeleted, 0));
    }
}
